package com.yesallchina.wxapp.officialaccount.api.beans;


import com.yesallchina.wxapp.officialaccount.api.enums.MessageEventTypeEnum;
import com.yesallchina.wxapp.officialaccount.utils.JacksonUtils;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.util.HashMap;
import java.util.Map;

@XmlRootElement(name = "xml")
public class MusicMessage extends Message {

	private Music Music;

	public MusicMessage() {
		super();
		super.setMsgType(MessageEventTypeEnum.MUSIC.getMsgType());
	}

	@XmlElement(name = "Music")
	public Music getMusic() {
		return Music;
	}

	public void setMusic(Music music) {
		this.Music = music;
	}

	public static class Music {
		private String Title;

		private String Description;
		/**
		 * 音乐链接 不可为空
		 */
		private String MusicUrl;
		/**
		 * 高品质音乐链接，wifi环境优先使用该链接播放音乐 不可为空
		 */
		private String HQMusicUrl;
		/**
		 * 缩略图的媒体ID 不可为空
		 */
		private String ThumbMediaId;

		@XmlElement(name = "Title")
		public String getTitle() {
			return Title;
		}

		public void setTitle(String title) {
			Title = title;
		}

		@XmlElement(name = "Description")
		public String getDescription() {
			return Description;
		}

		public void setDescription(String description) {
			Description = description;
		}

		@XmlElement(name = "MusicUrl")
		public String getMusicUrl() {
			return MusicUrl;
		}

		public void setMusicUrl(String musicUrl) {
			MusicUrl = musicUrl;
		}

		@XmlElement(name = "HQMusicUrl")
		public String getHQMusicUrl() {
			return HQMusicUrl;
		}

		public void setHQMusicUrl(String HQMusicUrl) {
			this.HQMusicUrl = HQMusicUrl;
		}

		@XmlElement(name = "ThumbMediaId")
		public String getThumbMediaId() {
			return ThumbMediaId;
		}

		public void setThumbMediaId(String thumbMediaId) {
			ThumbMediaId = thumbMediaId;
		}
	}

	@Override
	public String toCustomerMessage() {
		Map<String, Object> msg = new HashMap<>();
		msg.put("touser", getToUserName());
		msg.put("msgtype", MessageEventTypeEnum.MUSIC.getMsgType());
		Map<String, Object> music = new HashMap<>();
		music.put("musicurl", getMusic().getMusicUrl());
		music.put("hqmusicurl",getMusic().getHQMusicUrl());
		music.put("title",getMusic().getTitle());
		music.put("description",getMusic().getDescription());
		msg.put("music", music);
		return JacksonUtils.generate(msg);
	}

}
